package com.gouqi.mall.controller;

import com.gouqi.mall.domain.LoginInfo;
import com.gouqi.mall.domain.ProductBrand;
import com.gouqi.mall.service.PersonService;
import com.gouqi.mall.service.ProductBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/***
 * @author:xiaofei
 * @datetime:2020-4-24
 * @description:产品品牌控制器
 */
@CrossOrigin
@Api(basePath = "/api/v1", value = "产品品牌接口", description = "产品品牌接口")
@Component
@RestController
@RequestMapping(value = "/product/brand")
public class ProductBrandController extends BaseController {

    @Autowired
    @Qualifier("productBrandServiceImpl")
    private ProductBrandService service;

    @ResponseBody
    @RequestMapping(value = "/addOneBrand.do",method = RequestMethod.POST, produces = "application/json")
    @ApiOperation(value = "新增品牌",notes = "新增一个枸杞品牌",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "token",value = "用户token",required = true,dataType = "String")
    })
    public String addOneBrand(@RequestHeader String token,@RequestBody @Valid ProductBrand brand){
        return service.addOneBrand(brand);
    }

    @ResponseBody
    @RequestMapping(value = "/updateOneBrand.do",method = RequestMethod.PUT, produces = "application/json")
    @ApiOperation(value = "更新品牌",notes = "更新一个枸杞品牌",httpMethod = "PUT")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "token",value = "用户token",required = true,dataType = "String")
    })
    public String updateOneBrand(@RequestHeader String token,@RequestBody @Valid ProductBrand brand){
        return service.updateOneBrand(brand);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteOneBrand.do",method = RequestMethod.DELETE, produces = "application/json")
    @ApiOperation(value = "删除品牌",notes = "删除一个枸杞品牌",httpMethod = "DELETE")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "token",value = "用户token",required = true,dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "id",value = "产品品牌表id",required = true,dataType = "Integer"),
    })
    public String deleteOneBrand(@RequestHeader String token,@RequestParam Integer id){
        return service.deleteOneBrand(id);
    }

    @ResponseBody
    @RequestMapping(value = "/queryRankBrand.do?by=type",method = RequestMethod.GET, produces = "application/json")
    @ApiOperation(value = "搜索品牌",notes = "根据品牌类型查询前多少名品牌",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "token",value = "用户token",required = true,dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "type",value = "产品品牌类型",required = true,dataType = "String"),
    })
    public String queryRankBrand(@RequestHeader String token,@RequestParam String type){
        return service.queryRankBrand(type);
    }

    @ResponseBody
    @RequestMapping(value = "/queryAllBrands.do",method = RequestMethod.GET, produces = "application/json")
    @ApiOperation(value = "搜索品牌",notes = "根据品牌类型查询所有的品牌",httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "token",value = "用户token",required = true,dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "index",value = "当前页",required = true,dataType = "Integer"),
            @ApiImplicitParam(paramType = "query",name = "pageSize",value = "每页显示条数",required = true,dataType = "Integer")
    })
    public String queryAllBrands(@RequestHeader String token,@RequestParam Integer index,@RequestParam Integer pageSize){
        return service.queryAllBrands(index,pageSize);
    }

    @ResponseBody
    @RequestMapping(value = "/takeoffOneBrands.do",method = RequestMethod.PUT, produces = "application/json")
    @ApiOperation(value = "下架品牌",notes = "下架一个品牌",httpMethod = "PUT")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header",name = "token",value = "用户token",required = true,dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "id",value = "品牌表id",required = true,dataType = "Integer"),
            @ApiImplicitParam(paramType = "query",name = "takeoff",value = "是否下架",required = true,dataType = "Boolean"),
            @ApiImplicitParam(paramType = "query",name = "takeTime",value = "下架时间",required = true,dataType = "String"),
            @ApiImplicitParam(paramType = "query",name = "takeoffReason",value = "下架原因",required = true,dataType = "Integer")
    })
    public String takeoffOneBrands(@RequestHeader String token,@RequestParam Integer id,@RequestParam Boolean takeoff,
                                   @RequestParam String takeTime,@RequestParam String takeoffReason){
        return service.takeoffOneBrands(id,takeoff,takeTime,takeoffReason);
    }
}
